home *** CD-ROM | disk | FTP | other *** search
/ Freelog 117 / FreelogNo117-OctobreNovembre2013.iso / Programmation / jedit / jedit5.1.0install.exe / {app} / macros / Files / Delete_Current.bsh < prev    next >
Text File  |  2013-07-28  |  2KB  |  80 lines

  1. /*
  2.  * Delete_Current.bsh - Deletes the current
  3.  * buffer's file on disk, but doesn't close 
  4.  * the buffer.
  5.  *
  6.  * Copyright (C) 2003-2004 Ollie Rutherfurd <oliver@rutherfurd.net>
  7.  *
  8.  * $Id: Delete_Current.bsh 21353 2012-03-14 09:46:51Z jojaba_67 $
  9.  */
  10.  
  11. import javax.swing.SwingUtilities;
  12. import org.gjt.sp.jedit.io.*;
  13.  
  14. //Localization
  15. final static String NotOnDiskError = jEdit.getProperty("macro.rs.DeleteCurrent.NotOnDisk.error", "Buffer doesn't exist on disk.");
  16. final static String DeleteNotSupportError = jEdit.getProperty("macro.rs.DeleteCurrent.DeleteNotSupport.error", "doesn't support deleting.");
  17. final static String DeletedMessage = jEdit.getProperty("macro.rs.DeleteCurrent.Deleted.message", "Deleted:");
  18.  
  19. BufferStatusChecker(View view){
  20.     run(){
  21.         jEdit.checkBufferStatus(view);
  22.     }
  23.     return this;
  24. }
  25.  
  26.  
  27. void deleteCurrentBuffer(View view){
  28.     Buffer buffer = view.getBuffer();
  29.  
  30.     // don't bother deleting new buffers (don't exist on disk)
  31.     if(buffer.isNewFile()){
  32.         Macros.error(view, NotOnDiskError );
  33.         return;
  34.     }
  35.  
  36.     try{
  37.         String path = buffer.getPath();
  38.         VFS vfs = VFSManager.getVFSForPath(path);
  39.         int caps = vfs.getCapabilities();
  40.         int del = VFS.DELETE_CAP;
  41.         int res = caps & del;
  42.         if(res == 0){
  43.             Macros.error(view, "VFS " + vfs.getName() 
  44.                          + " " + DeleteNotSupportError);
  45.             return;
  46.         }
  47.     
  48.         Object session = null;
  49.         try{
  50.             session = vfs.createVFSSession(path,view);
  51.             if(vfs._delete(session,path,view)){
  52.                 view.getStatus().setMessageAndClear(DeletedMessage + " " + path);
  53.             }
  54.             // invoke buffer status check
  55.             SwingUtilities.invokeLater(BufferStatusChecker(view));
  56.         }
  57.         finally{
  58.             if(session != null)
  59.                 vfs._endVFSSession(session,view);
  60.         }
  61.     }
  62.     catch(Exception e){
  63.         Macros.error(view, e.toString());
  64.     }
  65. }
  66.  
  67. deleteCurrentBuffer(view);
  68.  
  69. /*
  70.  
  71.     <listitem>
  72.         <para><filename>Delete_Current.bsh</filename></para>
  73.         <abstract><para>
  74.         Deletes the current buffer's file on disk, but 
  75.         doesn't close the buffer.
  76.         </para></abstract>
  77.     </listitem>
  78.  
  79. */
  80.